<?php
include_once 'classes/DBClass.php';
include_once 'classes/User.php';
include_once 'classes/Campaign.php';
include_once 'classes/V_Campaign.php';
include_once 'classes/V_NCampaign.php';

class CampaignList {


	function CampaignList($timeInterval){
		if($timeInterval == "current")$this->displayCurrentList();
		elseif($timeInterval == "next")$this->displayNextList();
		else return false;
	}

	private function listCampaigns($timeInterval){

		$query = "SELECT * FROM `mf_campaign`";
		if($timeInterval == "current") {
			$query .= " WHERE `date_start` <= CURDATE() AND `date_finish` >= CURDATE()";
		}
		else if($timeInterval == "next"){
			$query .= "  WHERE `date_start` > CURDATE()";
		}

		$mysql = new DBClass();
		//Stored Procedure
		$campaigns = $mysql->Query($query);

		// campaign nesnesi listesi
		$campaignObjectList = array();
		$i = 0;
		foreach ($campaigns as $cmpgn){
			// yeni campaign nesnesi
			$campaignObject = new Campaign();
			// nesnenin verilerini ekleme
			$campaignObject->brand_id = $cmpgn[1];
			$campaignObject->name = $cmpgn[2];
			$campaignObject->date_start = $cmpgn[3];
			$campaignObject->date_finish = $cmpgn[4];
			// nesne listesine nesneyi ekleme
			$campaignObjectList[$i] = $campaignObject;
			$i++;
		}
			
		// return next campaign list
		return $campaignObjectList;
	}

	function displayCurrentList(){
		$campaigns = $this->listCampaigns("current");
		foreach ($campaigns as $campaign){
			$name = "campaign".$campaign->brand_id;
			new V_Campaign($campaign);
		}
	}
	function displayNextList(){
		$campaigns = $this->listCampaigns("next");
		new V_NCampaign($campaigns);
	}
}
?>